<?php 
//if( !is_admin() ){
    add_action('wp_ajax_show_all_articles', 'show_all_articles_callback');
    add_action('wp_ajax_nopriv_show_all_articles', 'show_all_articles_callback');

    function show_all_articles_callback() {
       $paged = isset($_POST['paged']) ? $_POST['paged'] : 1;
        $page_size = 15;        
        $query = new WP_Query(array('post_type' => 'post',
                                    'post_status' => 'published',
                                    'paged' => $paged,
                                    'posts_per_page' => $page_size,            
                                    'category__not_in' => (array) get_option('thestyle_exlcats_recent'),
                                    'orderby' => 'modified',
                                    'order' => 'DESC'
                                    ));
                  
        ?>	
	<?php while ( $query->have_posts() ) : $query->the_post(); ?>
	<?php 
                $biglayout = ( (bool) get_post_meta($post->ID,'et_bigpost',true) ) ? true : false;
                global $post;
                $thumb = '';
                $width = $biglayout ? 466 : 222;
                $height = 180;
                $classtext = '';
                $post_id = get_the_ID();
                $titletext = get_the_title();

                $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
                $thumb = $thumbnail["thumb"]; 
                ?>         
               
                <?php 
                    $excerpt = '';
                    if ($biglayout) 
                        $excerpt = truncate_post(650, false, $post);
                    else 
                        $excerpt = truncate_post(295, false, $post);
                    $link = get_permalink($post_id);
                    $title = '';
                      if ($biglayout) 
                        $title = truncate_title(50, false, $post);
                    else 
                        $title = truncate_title(20, false, $post);
                    
                    $month = get_the_time('M', $post);
                    $day = get_the_time('d', $post);
                    $categories = get_the_category(); 
                    $categorie_links = array();
                    if($categories){
                        foreach($categories as $category) {
                              $categorie_links[] = array("cate_link"=>get_category_link($category->term_id), "name"=>$category->name);
                        }
                    }
                    $post_item = array(
                        "post_title"=>$title,
                        "full_title"=>$titletext,
                        "thumbnail" => get_thumbnail_url($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext, false),
                        "excerpt" => $excerpt,
                        "post_link" => $link,
                        "month" => $month,
                        "day" => $day,
                        "categories" => $categorie_links,
                        "biglayout"=>$biglayout,
                        "posted_by" => get_the_author_link()
                        );
                    
                    $post_list[] = $post_item;
                ?>
        <?php endwhile;wp_reset_query(); ?>		

<?php
    //  print_r($post_list);
    //$datas = array("data" => $post_list);
    echo json_encode($post_list);
    die(1);
    }
//}

add_action( 'after_setup_theme', 'et_setup_theme' );
if ( ! function_exists( 'et_setup_theme' ) ){
	function et_setup_theme(){
		require_once(TEMPLATEPATH . '/epanel/custom_functions.php'); 

		require_once(TEMPLATEPATH . '/includes/functions/comments.php'); 

		require_once(TEMPLATEPATH . '/includes/functions/sidebars.php'); 

		load_theme_textdomain('TheStyle',get_template_directory().'/lang');

		require_once(TEMPLATEPATH . '/epanel/options_thestyle.php');

		require_once(TEMPLATEPATH . '/epanel/core_functions.php'); 

		require_once(TEMPLATEPATH . '/epanel/post_thumbnails_thestyle.php');
		
		include(TEMPLATEPATH . '/includes/widgets.php');
		
		require_once(TEMPLATEPATH . '/includes/additional_functions.php');
	}
}

add_action('wp_head','et_portfoliopt_additional_styles',100);
function et_portfoliopt_additional_styles(){ ?>
	<style type="text/css">
		#et_pt_portfolio_gallery { margin-left: -10px; }
		.et_pt_portfolio_item { margin-left: 11px; }
		.et_portfolio_small { margin-left: -38px !important; }
		.et_portfolio_small .et_pt_portfolio_item { margin-left: 26px !important; }
		.et_portfolio_large { margin-left: -12px !important; }
		.et_portfolio_large .et_pt_portfolio_item { margin-left: 13px !important; }
                #boxes div.entry.small, #boxes div.entry.big{
                    float:left;
                    margin-right: 20px;
                    margin-left:0px;

                }
	</style>
<?php }

function insertThumbnailRSS($content) {
	global $post;

	$thumb = ''; $thumb = get_post_meta($post->ID, 'Thumbnail',true);

	if ( has_post_thumbnail( $post->ID ) ){
		$content = '<p>' . get_the_post_thumbnail( $post->ID, 'medium' ) . '</p>' . $content;
	} else if ($thumb <> '') {
		$content = '<p>' . '<img src="'. et_new_thumb_resize( et_multisite_thumbnail($thumb), 300, 200, '', true ) .'"/>' . '</p>' . $content;
	}

	return $content;
}
add_filter('the_excerpt_rss', 'insertThumbnailRSS');
add_filter('the_content_feed', 'insertThumbnailRSS');

function register_main_menus() {
	register_nav_menus(
		array(
			'primary-menu' => __( 'Primary Menu' )
		)
	);
}
if (function_exists('register_nav_menus')) add_action( 'init', 'register_main_menus' );

if ( ! function_exists( 'et_list_pings' ) ){
	function et_list_pings($comment, $args, $depth) {
		$GLOBALS['comment'] = $comment; ?>
		<li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?> - <?php comment_excerpt(); ?>
	<?php }
} ?>